﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering;

namespace Peter.Logic.AvalonEdit
{
   /// <summary>
   /// A highlighter for the avalon edit control that will mark the error lines as red.
   /// </summary>
   public class ErrorLineHighlighter : DocumentColorizingTransformer
   {
      private readonly Int32Collection m_LineNumbers;

      /// <summary>
      /// Initializes a new error line highlighter.
      /// </summary>
      public ErrorLineHighlighter ()
      {
         this.m_LineNumbers = new Int32Collection ();
      }

      /// <summary>
      /// Gets the line numbers that are errors.
      /// </summary>
      public Int32Collection LineNumbers
      {
         get { return m_LineNumbers; }
      }

      /// <summary>
      /// Override this method to colorize an individual document line.
      /// </summary>
      protected override void ColorizeLine (DocumentLine line)
      {
         if (!line.IsDeleted && this.LineNumbers.Contains(line.LineNumber))
         {
            ChangeLinePart (line.Offset, line.EndOffset, ApplyChanges);
         }
      }

      private void ApplyChanges (VisualLineElement element)
      {
         // apply changes here
         element.TextRunProperties.SetForegroundBrush (Brushes.Red);
      }
   }
}